﻿using System;

namespace DotNetNuke.Modules._2DoTasks.Components.Utils
{
    public static class Extensions
    {
        /// <summary>
        /// Evaluates a hourminute string representation and collects the total minutes present
        /// </summary>
        /// <param name="hourMinute">hour minute in format HH:mm</param>
        /// <returns>returns total minutes</returns>
        public static int GetTotalMinutes(this string hourMinute)
        {
            if (hourMinute.IndexOf(":") > 0)
            {
                string[] arr = hourMinute.Split(':');
                int hours = int.Parse(arr[0].ToString());
                int mins = int.Parse(arr[1].ToString());
                if (hours >= 0 && hours < 24 && mins >= 0 && mins < 60)
                    return hours * 60 + mins;
                else
                    throw new InvalidCastException();
            }
            else
            {
                return int.Parse(hourMinute.ToString()) * 60;
            }
        }
    }
}